// AppSettings.cpp: implementation of the CAppSettings class.
//
//////////////////////////////////////////////////////////////////////

#include "AppSettings.h"

#include <coemain.h>		// For CCoeEnv class
#include <s32stor.h>		// For CDictionaryStore class
#include <TagChanger.rsg>	// For resource definition

#include "TagChangerApp.h"	// For UID difinition

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAppSettings::CAppSettings(CEikApplication& aApp) 
: iApp(aApp)
{
}

void CAppSettings::ConstructL()
{
    LoadL();
}

void CAppSettings::LoadL()
{
    CDictionaryStore* iniFile = iApp.OpenIniFileLC(CCoeEnv::Static()->FsSession());
	
	if (iniFile->IsPresentL(KUidTagChanger))
	{
		RDictionaryReadStream readStream;
		readStream.OpenLC(*iniFile, KUidTagChanger);
		//CleanupClosePushL(readStream);
		
		// Initialize settings
		TInt Len = readStream.ReadInt16L();
		readStream.ReadL(iLastPath, Len);

		RDebug::Print(iLastPath);
			
        CleanupStack::PopAndDestroy();
	}
	else
	{
		// ini doesn't exist, so use default values
		iLastPath = _L("");
	}
	
	CleanupStack::PopAndDestroy();    
}

void CAppSettings::StoreL()
{
    CDictionaryStore* iniFile = iApp.OpenIniFileLC(CCoeEnv::Static()->FsSession());
    RDictionaryWriteStream writeStream;

    writeStream.AssignLC(*iniFile, KUidTagChanger);
	
	RDebug::Print(iLastPath);
	
	// Clean old information
	//iniFile->Remove(KUidTagChanger);

    // You may support some simple versioning if you wish
    writeStream.WriteInt16L(iLastPath.Length());
	writeStream.WriteL(iLastPath, iLastPath.Length());
	
    writeStream.CommitL();
    iniFile->CommitL();

    CleanupStack::PopAndDestroy(&writeStream);
	CleanupStack::PopAndDestroy(iniFile);
}




